<template>
  <transition name="dialog-fade">
    <div v-if="visible" class="custom-dialog-overlay" @click.self="handleCancel">
      <div class="custom-dialog" :class="[`dialog-${type}`]">
        <div class="dialog-header">
          <div class="dialog-icon">
            {{ getIcon() }}
          </div>
          <h3 class="dialog-title">{{ title }}</h3>
          <button v-if="showClose" @click="handleCancel" class="dialog-close">✕</button>
        </div>
        <div class="dialog-body">
          <p v-html="message"></p>
        </div>
        <div class="dialog-footer">
          <button v-if="type === 'confirm'" @click="handleCancel" class="btn btn-secondary">
            {{ cancelText }}
          </button>
          <button @click="handleConfirm" class="btn btn-primary">
            {{ confirmText }}
          </button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  type: {
    type: String,
    default: 'alert', // alert, confirm, success, error, warning
    validator: (value) => ['alert', 'confirm', 'success', 'error', 'warning', 'info'].includes(value)
  },
  title: {
    type: String,
    default: '提示'
  },
  message: {
    type: String,
    required: true
  },
  confirmText: {
    type: String,
    default: '确定'
  },
  cancelText: {
    type: String,
    default: '取消'
  },
  showClose: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['confirm', 'cancel', 'close'])

const getIcon = () => {
  const icons = {
    success: '✅',
    error: '❌',
    warning: '⚠️',
    info: 'ℹ️',
    confirm: '❓',
    alert: '💡'
  }
  return icons[props.type] || '💡'
}

const handleConfirm = () => {
  emit('confirm')
  emit('close')
}

const handleCancel = () => {
  emit('cancel')
  emit('close')
}
</script>

<style scoped>
.custom-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 107, 157, 0.15);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}

.custom-dialog {
  background: #ffffff;
  border: 3px solid transparent;
  background-image: 
    linear-gradient(#fff, #fff),
    linear-gradient(135deg, #ff6b9d, #c471ed);
  background-origin: border-box;
  background-clip: padding-box, border-box;
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(255, 107, 157, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.5);
  min-width: 420px;
  max-width: 600px;
  animation: slideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
  position: relative;
}

.custom-dialog::before {
  content: '✨';
  position: absolute;
  top: 15px;
  right: 60px;
  font-size: 20px;
  opacity: 0.3;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(180deg); }
}

.dialog-header {
  padding: 24px 28px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 2px solid #fef5f8;
  background: linear-gradient(135deg, #fef5f8 0%, #fff0f6 100%);
  position: relative;
}

.dialog-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #ff6b9d, #c471ed, #12cad6);
}

.dialog-icon {
  width: 52px;
  height: 52px;
  font-size: 30px;
  line-height: 52px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.15), rgba(196, 113, 237, 0.15));
  border-radius: 16px;
  border: 2px solid rgba(255, 107, 157, 0.3);
  animation: bounce 0.6s ease, pulse 2s ease-in-out infinite;
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.2);
}

.dialog-title {
  flex: 1;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, #ff6b9d, #c471ed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
}

.dialog-title::before {
  content: '🌸';
  position: absolute;
  left: -30px;
  opacity: 0.4;
  animation: float 2s ease-in-out infinite;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: 2px solid rgba(255, 107, 157, 0.2);
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.1), rgba(196, 113, 237, 0.1));
  color: #ff6b9d;
  font-size: 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-close:hover {
  background: linear-gradient(135deg, #ff6b9d, #c471ed);
  color: white;
  transform: rotate(90deg) scale(1.1);
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.4);
}

.dialog-body {
  padding: 28px 32px;
  color: #2e3440;
  line-height: 1.8;
  font-size: 15px;
  background: #ffffff;
}

.dialog-body p {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: #6c7589;
}

.dialog-footer {
  padding: 20px 28px 28px;
  display: flex;
  justify-content: flex-end;
  gap: 14px;
  background: #fef5f8;
  position: relative;
}

.dialog-footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 107, 157, 0.2), transparent);
}

.btn {
  padding: 12px 28px;
  border: none;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 90px;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '✨';
  position: absolute;
  top: 50%;
  left: -25px;
  transform: translateY(-50%);
  opacity: 0;
  transition: all 0.3s ease;
  font-size: 12px;
}

.btn:hover::before {
  left: 12px;
  opacity: 1;
}

.btn-primary {
  background: linear-gradient(135deg, #ff6b9d, #c471ed);
  color: white;
  box-shadow: 0 4px 15px rgba(255, 107, 157, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #c471ed, #ff6b9d);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 25px rgba(196, 113, 237, 0.4);
}

.btn-primary:active {
  transform: translateY(-1px) scale(0.98);
}

.btn-secondary {
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.1), rgba(196, 113, 237, 0.1));
  color: #ff6b9d;
  border: 2px solid rgba(255, 107, 157, 0.3);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.2), rgba(196, 113, 237, 0.2));
  border-color: #ff6b9d;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.2);
}

/* 类型特定样式 - 二次元风格 */
.dialog-success .dialog-header,
.dialog-error .dialog-header,
.dialog-warning .dialog-header,
.dialog-info .dialog-header,
.dialog-confirm .dialog-header,
.dialog-alert .dialog-header {
  background: linear-gradient(135deg, #fef5f8 0%, #fff0f6 100%);
}

/* 图标背景色 - 渐变风格 */
.dialog-success .dialog-icon {
  background: linear-gradient(135deg, rgba(81, 207, 102, 0.2), rgba(81, 207, 102, 0.1));
  border-color: rgba(81, 207, 102, 0.4);
}

.dialog-error .dialog-icon {
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.2), rgba(255, 107, 107, 0.1));
  border-color: rgba(255, 107, 107, 0.4);
}

.dialog-warning .dialog-icon {
  background: linear-gradient(135deg, rgba(255, 169, 77, 0.2), rgba(255, 169, 77, 0.1));
  border-color: rgba(255, 169, 77, 0.4);
}

.dialog-info .dialog-icon {
  background: linear-gradient(135deg, rgba(18, 202, 214, 0.2), rgba(18, 202, 214, 0.1));
  border-color: rgba(18, 202, 214, 0.4);
}

.dialog-confirm .dialog-icon,
.dialog-alert .dialog-icon {
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.2), rgba(196, 113, 237, 0.1));
  border-color: rgba(255, 107, 157, 0.4);
}

/* 动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes bounce {
  0%, 100% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.1) rotate(-5deg);
  }
  50% {
    transform: scale(1.2) rotate(0deg);
  }
  75% {
    transform: scale(1.1) rotate(5deg);
  }
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(255, 107, 157, 0.2);
  }
  50% {
    box-shadow: 0 6px 20px rgba(255, 107, 157, 0.4);
  }
}

.dialog-fade-enter-active {
  animation: fadeIn 0.2s ease;
}

.dialog-fade-leave-active {
  animation: fadeIn 0.2s ease reverse;
}
</style>
